
#ifndef _TTG_MATH_RELATIONS_
#define _TTG_MATH_RELATIONS_
#include "Common/Definitions.h"

#include <cmath>

#ifdef __CUDACC__
#define TTG_INLINE __inline__ __host__ __device__
#define TTG_AMPERSAND
#else
#define TTG_INLINE inline
#define TTG_AMPERSAND &
#endif

namespace ttg
{
	namespace math
	{
		//Default epsilon
		static const float epsilon = 0.001f;

		template <class T>
		TTG_INLINE bool isZeroEps(T x, T eps)
				{ return abs(x) <= eps; }

		template <class T>
		inline bool isZero(T x)
				{ return isZeroEps<T>(x, epsilon); }
		//#define isZero(x) isZeroEps(x, epsilon)

		template <class T>
		inline bool isEqualEps(T x, T y, T eps)
				{ return fabs(x-y) <= eps; }
		//#define isEqualEps(x, y, eps) (fabs((x)-(y)) <= eps)

		template <class T>
		inline bool isEqual(T x, T y)
				{ return isEqualEps<T>(x, y, epsilon); }
		//#define isEqual(x, y) isEqualEps(x, y, epsilon)

		template <class T>
		inline bool isLesserEps(T x, T y, T eps)
				{ return x < y + eps; }
		//#define isLesserEps(x, y, eps) (x < y + eps)

		template <class T>
		inline bool isLesser(T x, T y)
				{ return isLesser<T>(x, y, epsilon); }
		//#define isLesser(x, y) isLesser(x, y, epsislon)

		template<class T>
		inline bool isGreaterEps(T x, T y, T eps)
				{ return x > y - eps; }
		//#define isGreaterEps(x, y) (x > y - eps)

		template <class T>
		inline bool isGreater(T x, T y)
				{ return isGreaterEps(x, y, epsilon); }
		//#define isGreater(x, y) isGreaterEps(x, y, epsilon)

		//Returns sign of a (as -1, 0 or 1).
		inline int getSign(float a)
		{
			return a > 0.0f ? 1 :
				   a < 0.0f ? -1 : 0;
		}

		inline bool isSignEqual(float a, float b)
		{
			return a * b > 0.0f ? true : false;
		}

		inline bool isSignEqual(int a, int b)
		{
			return a * b > 0 ? true : false;
		}
	}
}

#endif
